package com.test.daily.leetcode.y2021.m10.day1021;

/**
 * @descriptions: plusOne
 * @author: Tom
 * @date: 2021/10/21 上午 09:05
 * @version: 1.0
 */
public class Code01_PlusOne {
    public static void main(String[] args) {
        int[] arr = new int[]{9};
        Code01_PlusOne cp = new Code01_PlusOne();
        int[] answer = cp.plusOne(arr);
        for (int element : answer) {
            System.out.print(element + " ");
        }
    }

    public int[] plusOne(int[] digits) {
        int N = digits.length;
        int[] source = digits;
        int[] ansArr = new int[N + 1];
        source[N - 1] += 1;
        for (int i = source.length - 1; i > 0; i--) {
            if (source[i] >= 10) {
                source[i] -= 10;
                source[i - 1] += 1;
            }
        }
        if (source[0] >= 10) {
            ansArr[0] = source[0] / 10;
            ansArr[1] = source[0] - 10;
            for (int i = 1; i < N - 1; i++) {
                ansArr[i + 1] = source[i];
            }
            return ansArr;
        }
        return source;
    }
}
